package com.ywl.study.sharding.common.algorithm;

import org.apache.shardingsphere.api.sharding.standard.PreciseShardingAlgorithm;
import org.apache.shardingsphere.api.sharding.standard.PreciseShardingValue;

import java.util.Collection;

public class PreciseModuloShardingTableAlgorithm implements PreciseShardingAlgorithm<Long> {
    @Override
    public String doSharding(Collection<String> tableNames, PreciseShardingValue<Long> shardingValue) {
        String stuff=String.valueOf(shardingValue.getValue()%2);
        for (String tableName : tableNames) {
            if(tableName.endsWith(stuff)){
                return tableName;
            }
        }
        throw new UnsupportedOperationException();
    }
}
